package com.example.interview.no0102.solution;

import com.example.interview.no0102.Solution;

/**
 * @Description 解答-判定是否互为字符重排
 * @ClassName ArraySolution
 * @Author Administrator
 * @Date 2020/7/7 19:36
 * @Version 1.0.0
 */
public class ArraySolution implements Solution {
    @Override
    public boolean CheckPermutation(String s1, String s2) {
        int l1 = s1.length();
        int l2 = s2.length();
        if(l1 != l2){
            return false;
        }

        int []index = new int[128];
        for(int i=0; i<l1; i++){
            index[s1.charAt(i)]++;
            index[s2.charAt(i)]--;
        }
        for(int i=0; i<128; i++){
            if(index[i] != 0) {
                return false;
            }
        }
        return true;
    }
}
